import { computed } from 'vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import store from '@/utils/store'
import canvas from './modules/canvas'
import css3 from './modules/css3'
import threeJs from './modules/threeJs'
import algorithm from './modules/algorithm'
import designMode from './modules/design-mode'
import webrtc from './modules/webrtc'

export const baseRoutes: Array<RouteRecordRaw> = [
  {
    path: 'dashboard',
    name: 'Dashboard',
    meta: { title: 'dashboard' },
    component: () => import('@/pages/dashboard/index.vue')
  },
  canvas,
  css3,
  threeJs,
  algorithm,
  designMode,
  webrtc
]

export const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    redirect: '/dashboard',
    component: () => import('@/pages/home/index.vue'),
    children: baseRoutes
  }
]
const loadingBar = computed(() => store.loadingBar)

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach(() => {
  loadingBar.value?.start()
})
router.afterEach(() => {
  loadingBar.value?.finish()
})

export default router
